package main

import "time"

// select 多路复用
func main() {
	// select 就是 routine 中的switch *** case
	intChan := make(chan int, 10)
	for i := 0; i < 10; i++ {
		intChan <- i
	}

	outChan := make(chan int, 10)
	for i := 0; i < 10; i++ {
		outChan <- i
	}

	// 使用多路复用不需要关闭 channel
	for {
		select {
		case i := <-intChan:
			println("intChan : ", i)
			time.Sleep(time.Microsecond * 20)
		case j := <-outChan:
			println("outChan : ", j)
			time.Sleep(time.Microsecond * 20)
		default:
			println("default")
			return
		}
	}
}
